package com.example.taobao

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomnavigation.BottomNavigationView

class zhuyem : AppCompatActivity() {
    private lateinit var adapter: FragmentAdapter
    private lateinit var bnView: BottomNavigationView
    private lateinit var viewPager: ViewPager
    private var fragments:MutableList<Fragment> = ArrayList()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_zhuyem)
        supportActionBar?.hide()

        bnView = findViewById(R.id.nav_bottom)
        viewPager = findViewById(R.id.view_pager)
        fragments.add(HomePage())
        fragments.add(FragmentWeiTao())
        fragments.add(Fragment_xiaoxi())
        fragments.add(Fragment_gouwuche())
        fragments.add(Fragment_mine())
        adapter = FragmentAdapter(
            fragments,
            supportFragmentManager
        )
        viewPager.adapter = adapter

        bnView.setOnNavigationItemSelectedListener { menuItem ->
            when (menuItem.itemId) {
                R.id.nav_home -> viewPager.currentItem = 0
                R.id.nav_find -> viewPager.currentItem = 1
                R.id.nav_message -> viewPager.currentItem = 2
                R.id.nav_cart->viewPager.currentItem=3
                R.id.nav_mine -> viewPager.currentItem = 4
            }
            false
        }

        viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(i: Int, v: Float, i1: Int) {}
            override fun onPageSelected(i: Int) {
                //将滑动到的页面对应的 menu 设置为选中状态
                bnView.menu.getItem(i).isChecked = true
            }

            override fun onPageScrollStateChanged(i: Int) {}
        })

    }
    override fun onResume() {
        super.onResume()
//        val tag = intent.getIntExtra("tag", 0)
//        if (tag == 5) {
//            val fiveFragment = Fragment_mine()
//            val manager = supportFragmentManager
//            val fragmentTransaction: FragmentTransaction = manager.beginTransaction()
//           // fragmentTransaction.replace(R.id.nav_mine, fiveFragment)
//            fragmentTransaction.commit()
//            super.onResume()
//        }
//        if (tag == 3) {
//            val threeFragment = Fragment_xiaoxi()
//            val manager = supportFragmentManager
//            val fragmentTransaction: FragmentTransaction = manager.beginTransaction()
//           // fragmentTransaction.replace(R.id.nav_mine, threeFragment)
//            fragmentTransaction.commit()
//            super.onResume()
//        }
//        if (tag == 4) {
//            val fourFragment = Fragment_gouwuche()
//            val manager = supportFragmentManager
//            val fragmentTransaction: FragmentTransaction = manager.beginTransaction()
//           // fragmentTransaction.replace(R.id.nav_mine, fourFragment)
//            fragmentTransaction.commit()
//            super.onResume()
//        }
        val ins = intent.getIntExtra("id", 0  )


    }
}